<?php

class Mprofile extends CI_Model {
	
	public $table = 'tbl_profile';
	public $pri_key="pro_id";
	public $lang="pro_lang";

	function __construct()

	{

		parent::__construct();

	}
	function load_profile($lang)
	{
		$this->db->where($this->lang,$lang);
		return $this->db->get($this->table)->row_array();
	}
	
	function delete()

	{

		if (isset($_POST['checkbox1']))

		{
			

			foreach($_POST['checkbox1'] as $id) {

			//	$row = $this->info_from_id($id);

		

				//xoa file

		//		if ($row['avatar'] != 'null') unlink($row['avatar']);

		

				//xoa CSDL

			//	$sql = "DELETE FROM human_resources WHERE id=$id";
				//$delete = array("deleted"=>"1");
				

			
				$this->db->where($this->pri_key, $id);
				$this->db->delete($this->table); 
				//$this->db->query($sql);

			}			

		}

	}	

	public function insert($data){

		if($this->db->insert($this->table,$data))
			return true;
		
		return false;

	}
		function update($data,$id,$lang)
	{
		if(is_numeric($id) && $id !='')
		{
	
			
			$this->db->where($this->pri_key,$id);
			$this->db->where($this->lang,$lang);
			
			if($this->db->update($this->table,$data))
							
				return true;
			return false;
			
			
		}
		return false;
	}
	
		public function get_manu($lang)
	{
		$this->db->where('ori_lang',$lang);
		$query = $this->db->get('tbl_origin');
		if($query->num_rows() >0)
			return $query->result_array();
		return false;
	}
	
	public function info_from_id($id)
	{
		if(is_numeric($id) && $id !="")
		{
		$this->db->where($this->pri_key.' =',$id);
		return $this->db->get($this->table)->result_array();
		}
		else
			return false;
	}
	public function check_name($name,$id="")
	{
		$this->db->where($this->name.' =',$name);
		if($this->db->count_all($this->table) >0)
			return true; // email nay da ton tai va ko su dung duoc
		return false; // co the su dung email nay
	}
	
	
	public function check_email($email)
	{
		$this->db->where('user_email =',$email);
		if($this->db->count_all($this->table) >0)
			return true; // email nay da ton tai va ko su dung duoc
		return false; // co the su dung email nay
			
 	}
	public function list_data($num='',$off='')
	{
		$this->db->limit($off,$num);
		 
		if($this->db->count_all($this->table) >0)
			//return $this->db->get($this->table)->result_array();
			{
	$this->db->order_by($this->table.".".$this->pri_key, "desc");
	return $this->db->get($this->table)->result_array();
			}
		return false;
	}
	// dem so record 
	function count_all()
	{
		return $this->db->count_all_results($this->table);
	}
	
	public function count_prod_from_ct($id)
	{
	//$this->db->select('sub_categories.*,products.*,categories.*,image,price_old,price_new,unit.id as unit_id,unit.name as unit_name');
		$this->db->where("pro_ct",$id);
///		$this->db->join("sub_categories","sub_categories.sub_cate_id = products.sub_id");

	$query =$this->db->get("tbl_profile");

		return $query->num_rows();

	
	}
public function del_item($id)
	{
		$this->db->where($this->pri_key, $id);
		$this->db->delete($this->table); 
			
	}

}//end model class





/* End of file mhumans.php */

/* Location: ./system/application/models/mhumans.php */

?>